package com.ohos.carbon.slice;

import com.ohos.carbon.ResourceTable;
import com.ohos.carbon.model.DataBean;
import com.ohos.carbon.slice.demos.MusicplayerSlice;
import com.ohos.carbon.slice.demos.ProfileSlice;
import com.ohos.carbon.slice.demos.SearchToolbarSlice;
import com.ohos.carbon.slice.widgets.*;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.Image;
import ohos.agp.components.ListContainer;
import ohos.agp.components.Text;
import ohos.agp.components.element.Element;
import ohos.agp.components.element.ElementScatter;
import ohos.agp.components.element.VectorElement;

import java.util.ArrayList;

import static com.ohos.carbon.slice.MainAbilitySlice.preferences;


public class WhatsSlice extends AbilitySlice {

    private Image back_button;
    private Text text_title;
    private ListContainer listContainer;
    private ArrayList<DataBean> mList;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_whats);
        initData();
        initView();
    }

    private void initData() {
        mList = new ArrayList<>();
        VectorElement parse = (VectorElement) ElementScatter.getInstance(getContext()).parse(ResourceTable.Graphic_ic_wrap_text_black_24dp);
        Element element = ElementScatter.getInstance(getContext()).parse(ResourceTable.Graphic_ic_warning_black_24dp);
        Element starFavour = ElementScatter.getInstance(getContext()).parse(ResourceTable.Graphic_ic_star_gray_24dp);
        Element favour = ElementScatter.getInstance(getContext()).parse(ResourceTable.Graphic_ic_star_border_black_24dp);
        Element font = ElementScatter.getInstance(getContext()).parse(ResourceTable.Graphic_ic_font_download_black_24dp);
        Element menu = ElementScatter.getInstance(getContext()).parse(ResourceTable.Graphic_ic_menu_black_24dp);
        Element search = ElementScatter.getInstance(getContext()).parse(ResourceTable.Graphic_carbon_search);
        Element player = ElementScatter.getInstance(getContext()).parse(ResourceTable.Graphic_ic_play_arrow_black_24dp);
        Element person = ElementScatter.getInstance(getContext()).parse(ResourceTable.Graphic_ic_person_black_24dp);
        Element gesture = ElementScatter.getInstance(getContext()).parse(ResourceTable.Graphic_ic_gesture_black_24dp);
        Element checkbox = ElementScatter.getInstance(getContext()).parse(ResourceTable.Graphic_ic_check_box_black_24dp);
        Element circle = ElementScatter.getInstance(getContext()).parse(ResourceTable.Graphic_ic_add_circle_black_24dp);
        mList.add(new DataBean(null, "These samples are new or have significant changes sine the previous release", null, null));
        mList.add(new DataBean(null, "Buttons", null, preferences.getBoolean("Buttons", false) ? starFavour : favour));
        mList.add(new DataBean(parse, "FlowLayout & Chips", null, preferences.getBoolean("FlowLayout & Chips", false) ? starFavour : favour));
        mList.add(new DataBean(null, "Shadow", null, preferences.getBoolean("Shadow", false) ? starFavour : favour));
        mList.add(new DataBean(null, "BottomNavigationView", null, preferences.getBoolean("BottomNavigationView", false) ? starFavour : favour));
        mList.add(new DataBean(font, "XML Font", null, preferences.getBoolean("XML Font", false) ? starFavour : favour));
        mList.add(new DataBean(null, "Backdrop", null, preferences.getBoolean("Backdrop", false) ? starFavour : favour));
        mList.add(new DataBean(menu, "Menus", null, preferences.getBoolean("Menus", false) ? starFavour : favour));
        mList.add(new DataBean(null, "Bar chart", element, preferences.getBoolean("Bar chart", false) ? starFavour : favour));
        mList.add(new DataBean(null, "Line chart", element, preferences.getBoolean("Line chart", false) ? starFavour : favour));
        mList.add(new DataBean(search, "Search Toolbar", null, preferences.getBoolean("Search Toolbar", false) ? starFavour : favour));
        mList.add(new DataBean(player, "Music player", element, preferences.getBoolean("Music player", false) ? starFavour : favour));
        mList.add(new DataBean(person, "Profile", null, preferences.getBoolean("Profile", false) ? starFavour : favour));
        mList.add(new DataBean(checkbox, "CheckBoxes & RadioButtons", null, preferences.getBoolean("CheckBoxes & RadioButtons", false) ? starFavour : favour));
        mList.add(new DataBean(gesture, "Gesture detector", null, preferences.getBoolean("Gesture detector", false) ? starFavour : favour));
        mList.add(new DataBean(circle, "Floating Action Button", null, preferences.getBoolean("Floating Action Button", false) ? starFavour : favour));
        mList.add(new DataBean(null, "Banner", null, preferences.getBoolean("Banner", false) ? starFavour : favour));
        mList.add(new DataBean(null, "NavigationView", element, preferences.getBoolean("NavigationView", false) ? starFavour : favour));

    }

    private void initView() {
        back_button = (Image) findComponentById(ResourceTable.Id_back_button);
        text_title = (Text) findComponentById(ResourceTable.Id_title_text);
        text_title.setText("What's new");
        listContainer = (ListContainer) findComponentById(ResourceTable.Id_listview);
        back_button.setImageElement(ElementScatter.getInstance(getContext()).parse(ResourceTable.Graphic_carbon_uparrow));
        listContainer.setItemProvider(new WhatsProvider(mList, getContext()));
        listContainer.setItemClickedListener(new ListContainer.ItemClickedListener() {
            @Override
            public void onItemClicked(ListContainer listContainer, Component component, int i, long l) {
                Intent intent = new Intent();
                switch (i) {
                    case 1:
                        present(new ButtonsSlice(), intent);
                        break;
                    case 2:
                        present(new FolwLayoutSlice(), intent);
                        break;
                    case 3:
                        present(new ShadowSlice(), intent);
                        break;
                    case 4:
                        present(new BottomNavigationSlice(), intent);
                        break;
                    case 5:
                        present(new XmlFontSlice(), intent);
                        break;
                    case 6:
                        present(new BackdropSlice(), intent);
                        break;
                    case 7:
                        present(new MenusSlice(), intent);
                        break;
                    case 8:
                        present(new HistogramViewDemo(), intent);
                        break;
                    case 9:
                        present(new ChartViewDemo(), intent);
                        break;
                    case 10:
                        present(new SearchToolbarSlice(), intent);
                        break;
                    case 11:
                        present(new MusicplayerSlice(), intent);
                        break;
                    case 12:
                        present(new ProfileSlice(), intent);
                        break;
                    case 13:
                        present(new CheckBoxesSlice(), intent);
                        break;
                    case 14:
                        present(new GesturedetectorSlice(), intent);
                        break;
                    case 15:
                        present(new FloatingSlice(), intent);
                        break;
                    case 16:
                        present(new BannerSlice(), intent);
                        break;
                    case 17:
                        present(new NavigationViewSlice(), intent);
                        break;
                }
            }
        });
        //点击返回按钮
        back_button.setClickedListener(component -> {
            onBackPressed();
        });


    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
